package com.peng.crm.workbench.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.peng.crm.commons.utils.UUIDUtil;
import com.peng.crm.workbench.dao.ActivityDao;
import com.peng.crm.workbench.dao.ClueActivityRelationDao;
import com.peng.crm.workbench.entity.Activity;
import com.peng.crm.workbench.entity.ClueActivityRelation;
import com.peng.crm.workbench.service.ClueActivityRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("clueActivityRelationService")
public class ClueActivityRelationServiceImpl implements ClueActivityRelationService {

    @Autowired
    private ClueActivityRelationDao clueActivityRelationDao;

    @Autowired
    private ActivityDao activityDao;

    @Override
    public Map<String, Object> pagelistactivity(Integer pageNumber, Integer pageSize, String clueId) {
        PageHelper.startPage(pageNumber,pageSize);
        PageInfo<Activity> pageInfo = new PageInfo(clueActivityRelationDao.pagelistactivity(clueId));
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("list",pageInfo.getList());
        pageMap.put("total",pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public Map<String, Object> selectList(Integer pageNumber,Integer pageSize,String activityName,String clueId) {
        PageHelper.startPage(pageNumber,pageSize);

        HashMap<String, String> map = new HashMap<>();
        map.put("id",clueId);
        map.put("name",activityName);
        PageInfo<Activity> pageInfo = new PageInfo(clueActivityRelationDao.select(map));
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("list",pageInfo.getList());
        pageMap.put("total",pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public Boolean deleteById(String id) {
        return clueActivityRelationDao.deleteById(id)>0;
    }

    @Override
    public Boolean inserts(String clueId, String[] activityId) {
        int activityIdlength = activityId.length;
        List<ClueActivityRelation> list = new ArrayList<>();
        for (int i=0;i<activityIdlength;i++){
            list.add(new ClueActivityRelation(UUIDUtil.getUUID(),clueId,activityId[i]));
        }
        return clueActivityRelationDao.inserts(list);
    }



}
